<!DOCTYPE html>
<html>
<head>
    <title>图片上传与展示</title>
</head>
<body>
<h2>上传图片</h2>
<!--<input type="file" id="imageInput">-->
<!--<button onclick="uploadImage()">上传图片</button>-->

<!--<h2>展示图片</h2>-->
<!--<div id="imageContainer"></div>-->

<form  id="saveAgent" action="hksEducation/addSchool" method="POST" enctype="multipart/form-data">
     <div>学校编码：<input type="text" name="schoolCode" /> </div>
    <div>标题：<input type="text" name="title" /></div>
    <div>类型：<input type="number" name="schoolType" /></div>
    <div>标签：<input type="text" name="label" /></div>
    <div>学校概括：<input type="text" name="schoolOverview" /></div>
    <div>招生简章：<input type="file" name="StudentsGuide" /></div>
    <div>webUrl：<input type="text" name="webUrl" /></div>
    <div>schoolPhone：<input type="text" name="schoolPhone" /></div>
     <div>学校图标：<input type="file" name="picUrl" /></div>
     <div>学校介绍图片：<input type="file" name="schoolPic" /></div>
     <div>视频：<input type="file" name="schoolVideo" /></div>
     <div>长图介绍：<input type="file" name="schoolPiiic" /></div>
     <div><input type="submit" value="提交" id="submitBnt"></div>
</form>


<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<form  id="updateContactPhone" action="hksEducation/updateContactPhone" method="GET">
    <div>修改联系电话：<input type="text" name="contactPhone" /> <input type="submit" value="提交" id="submitcontactPhoneBnt"></div>
</form>

<br>
<br>
<br>
<form  id="updateExamTime" action="hksEducation/updateExamTime" method="GET">
    <div>修改中考时间：格式为2024-7-15<input type="text" name="examTime" /> <input type="submit" value="提交" id="submitupdateExamTime"></div>
</form>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div >
    <button onclick="window.location.href='./querySchool.html'" type="button" id="add">查看所有学校</button>

</div>


<script>
    function uploadImage() {
        var fileInput = document.getElementById('imageInput');
        var file = fileInput.files[0];

        var formData = new FormData();
        formData.append('file', file);

        fetch('/upload', {
            method: 'POST',
            body: formData
        })
            .then(response => response.text())
            .then(result => {
                if (result === '上传成功') {
                    showImage(file.name);
                } else {
                    console.log('上传失败');
                }
            })
            .catch(error => console.error('Error:', error));
    }

    function showImage(fileName) {
        var imageContainer = document.getElementById('imageContainer');
        var imgElement = document.createElement('img');
        imgElement.src = '/' + fileName;
        imageContainer.appendChild(imgElement);
    }
</script>
</body>
</html>
